Vue.component('Update', {
	template: `
		<el-dialog title="修改" width="600px" class="icon-dialog" :visible.sync="show" @open="open" :before-close="closeForm" append-to-body>
			<el-form :size="size" ref="form" :model="form" :rules="rules" :label-width=" ismobile()?'90px':'16%'">
				<el-row >
					<el-col :span="24">
						<el-form-item label="名称" prop="children_name">
							<el-input  v-model="form.children_name" autoComplete="off" clearable  placeholder="请输入名称"></el-input>
						</el-form-item>
					</el-col>
				</el-row>
				<el-row >
					<el-col :span="24">
						<el-form-item label="昵称" prop="children_nickname">
							<el-input  v-model="form.children_nickname" autoComplete="off" clearable  placeholder="请输入昵称"></el-input>
						</el-form-item>
					</el-col>
				</el-row>
				<el-row >
					<el-col :span="24">
						<el-form-item label="性别" prop="children_sex">
							<el-radio-group v-model="form.children_sex">
								<el-radio :label="1">男</el-radio>
								<el-radio :label="0">女</el-radio>
							</el-radio-group>
						</el-form-item>
					</el-col>
				</el-row>
				<el-row >
					<el-col :span="24">
						<el-form-item label="出生日期" prop="children_birth">
							<el-date-picker value-format="yyyy-MM-dd HH:mm:ss" type="datetime" v-model="form.children_birth" clearable placeholder="请输入出生日期"></el-date-picker>
						</el-form-item>
					</el-col>
				</el-row>
				<el-row >
					<el-col :span="24">
						<el-form-item label="年级" prop="children_grade">
							<el-select   style="width:100%" v-model="form.children_grade" filterable clearable placeholder="请选择年级">
								<el-option v-for="(item,i) in children_grades" :key="i" :label="item.key" :value="item.val"></el-option>
							</el-select>
						</el-form-item>
					</el-col>
				</el-row>
				<el-row >
					<el-col :span="24">
						<el-form-item label="备注" prop="children_remark">
							<el-input  type="textarea" autoComplete="off" v-model="form.children_remark"  :autosize="{ minRows: 2, maxRows: 4}" clearable placeholder="请输入备注"/>
						</el-form-item>
					</el-col>
				</el-row>
				<el-row >
					<el-col :span="24">
						<el-form-item label="补习科目" prop="tutoring_subject">
							<el-select multiple style="width:100%" v-model="form.tutoring_subject" filterable clearable placeholder="请选择补习科目">
								<el-option v-for="(item,i) in tutoring_subjects" :key="i" :label="item.key" :value="item.val.toString()"></el-option>
							</el-select>
						</el-form-item>
					</el-col>
				</el-row>
				<el-row >
					<el-col :span="24">
						<el-form-item label="学习目标" prop="learning_goal">
							<el-input  v-model="form.learning_goal" autoComplete="off" clearable  placeholder="请输入学习目标"></el-input>
						</el-form-item>
					</el-col>
				</el-row>
				<el-row >
					<el-col :span="24">
						<el-form-item label="家长ID" prop="parent_id">
							<el-input  v-model="form.parent_id" autoComplete="off" clearable  placeholder="请输入家长ID"></el-input>
						</el-form-item>
					</el-col>
				</el-row>
				<el-row >
					<el-col :span="24">
						<el-form-item label="家长名称" prop="parent_name">
							<el-input  v-model="form.parent_name" autoComplete="off" clearable  placeholder="请输入家长名称"></el-input>
						</el-form-item>
					</el-col>
				</el-row>
				<el-row >
					<el-col :span="24">
						<el-form-item label="创建时间" prop="create_time">
							<el-date-picker value-format="yyyy-MM-dd HH:mm:ss" type="datetime" v-model="form.create_time" clearable placeholder="请输入创建时间"></el-date-picker>
						</el-form-item>
					</el-col>
				</el-row>
			</el-form>
			<div slot="footer" class="dialog-footer">
				<el-button :size="size" :loading="loading" type="primary" @click="submit" >
					<span v-if="!loading">确 定</span>
					<span v-else>提 交 中...</span>
				</el-button>
				<el-button :size="size" @click="closeForm">取 消</el-button>
			</div>
		</el-dialog>
	`
	,
	components:{
	},
	props: {
		show: {
			type: Boolean,
			default: false
		},
		size: {
			type: String,
			default: 'small'
		},
		info: {
			type: Object,
		},
	},
	data(){
		return {
			form: {
				children_name:'',
				children_nickname:'',
				children_sex:1,
				children_birth:'',
				children_grade:'',
				children_remark:'',
				tutoring_subject:[],
				learning_goal:'',
				parent_id:'',
				parent_name:'',
				create_time:'',
				update_time:'',
			},
			children_grades:[],
			tutoring_subjects:[],
			loading:false,
			rules: {
			}
		}
	},
	watch:{
		show(val){
			if(val){
				axios.post(base_url + '/Parents.Children/getFieldList').then(res => {
					if(res.data.status == 200){
						this.children_grades = res.data.data.children_grades
						this.tutoring_subjects = res.data.data.tutoring_subjects
					}
				})
			}
		}
	},
	methods: {
		open(){
			this.form = this.info
			this.form.children_birth = parseTime(this.form.children_birth)
			this.setDefaultVal('tutoring_subject')
		},
		submit(){
			this.$refs['form'].validate(valid => {
				if(valid) {
					this.loading = true
					axios.post(base_url + '/Parents.Children/update',this.form).then(res => {
						if(res.data.status == 200){
							this.$message({message: res.data.msg, type: 'success'})
							this.$emit('refesh_list')
							this.closeForm()
						}else{
							this.loading = false
							this.$message.error(res.data.msg)
						}
					}).catch(()=>{
						this.loading = false
					})
				}
			})
		},
		setDefaultVal(key){
			if(this.form[key] == null || this.form[key] == ''){
				this.form[key] = []
			}
		},
		closeForm(){
			this.$emit('update:show', false)
			this.loading = false
			if (this.$refs['form']!==undefined) {
				this.$refs['form'].resetFields()
			}
		},
	}
})
